﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.Base
@using ZBJF.Warranty.Common.Enums.Certificate
@using ZBJF.Warranty.Common.Enums.InsuranceProducts
@using ZBJF.Warranty.WebProvider
@model ZBJF.Warranty.Model.ViewModel.Order.InsuranceOrderModel
@{
    ViewBag.Title = "投保信息填写";
    var sellerId = Model.SellerID > 0 ? Model.SellerID : long.Parse(Request["SellerId"] ?? "0");
    var sellerEmployeeID = Model.SellerEmployeeID > 0 ? Model.SellerEmployeeID : long.Parse(Request["SellerEmployeeID"] ?? "0");
    if (sellerId <= 0 || sellerEmployeeID <= 0)//未登录或没有相关信息
    {
        Response.Redirect("/home");
    }
}
<div class="desc_forward_title" onclick="history.back(-1)">
    投保信息填写
</div>
<div class="weui-cell">
    @Model.SellerInsuranceProducts.ProductName
    <div class="weui-cell__bd price_desc align-right">
        @Model.SellerInsuranceProducts.SaleRetailPrice.ToString("c")
    </div>
</div>
<div class="space-4"></div>
<div>
    @using (Html.BeginForm("NextToConfirmInsuranceOrder", "InsuranceOrder", FormMethod.Post, new { id = "mvcForm", @class = "create-order-form" }))
    {
        <div class="weui-cells__title">设备信息</div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">品牌</label>
            </div>
            <div class="weui-cell__bd weui-msg__desc align-right">
                @Model.ProductBrandName
                @Html.HiddenFor(m => m.SellerID)
                @Html.HiddenFor(m => m.SellerEmployeeID)
                @Html.HiddenFor(m => m.SellerInsuranceProducts.ID)
                @Html.HiddenFor(m => m.SellerInsuranceProducts.ProductName)
                @Html.HiddenFor(m => m.SellerInsuranceProducts.SaleRetailPrice)
                @Html.HiddenFor(m => m.ProductBrandName)
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">型号</label>
            </div>
            <div class="weui-cell__bd weui-msg__desc align-right">
                @Model.ProductModelName
                @Html.HiddenFor(m => m.ProductModelName)
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">IMEI</label>
            </div>
            <div class="weui-cell__bd weui-msg__desc align-right">
                @Model.IMEI
                @Html.HiddenFor(m => m.IMEI)
            </div>
        </div>
        <div class="space-4"></div>
        <div class="weui-cells__title">投保信息</div>
        @Html.AntiForgeryToken()
        @Html.Hidden("ID")
        @Html.Hidden("SellerID", sellerId)
        @Html.Hidden("SellerEmployeeID", sellerEmployeeID)
        <div class="weui-cell">
            姓名：
            <div class="weui-cell__bd weui-cell_primary">
                @Html.TextBoxFor(m => m.UserName, new { validate = "{required:true,messages:{required:'请输入姓名'}}", @class = "weui-input", placeholder = "请输入姓名" })
            </div>
        </div>
        <div class="weui-cell padding-0 padding-l-10">
            证件类型：
            <div class="weui-cell__bd weui-cell_primary">
                @Html.DropDownListFor(m => m.CertificateType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(UserCertificateType)), new { validate = "{required:true,messages:{required:'请选择证件类型'}}", @class = "weui-select" })
            </div>
        </div>
        <div class="weui-cell">
            证件号码：
            <div class="weui-cell__bd weui-cell_primary">
                @Html.TextBoxFor(m => m.CertificateNO, new { validate = "{required:true,messages:{required:'请输入正确的证件号码'}}", @class = "weui-input", placeholder = "请输入正确的证件号码" })
            </div>
        </div>
        <div class="weui-cell">
            生日：
            <div class="weui-cell__bd weui-cell_primary">
                @Html.TextBoxFor(m => m.BirthDay, new { validate = "{required:true,messages:{required:'请选择出生日期'}}", @class = "weui-input", placeholder = "请选择出生日期" })
            </div>
        </div>
        <div class="weui-cell padding-0 padding-l-10">
            性别：
            <div class="weui-cell__bd weui-cell_primary">
                @Html.DropDownListFor(m => m.Sex, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(SexEnums)), new { validate = "{required:true,messages:{required:'请选择性别'}}", @class = "weui-select" })
            </div>
        </div>
        <div class="weui-cell">
            手机号码：
            <div class="weui-cell__bd weui-cell_primary">
                @Html.TextBoxFor(m => m.UserPhone, new { validate = "{required:true,isTelphone:true,messages:{required:'请输入联系电话',isTelphone:'请输入正确的手机号码'}}", @class = "weui-input", placeholder = "请输入正确的手机号码" })
            </div>
        </div>
        <div class="weui-cell">
            电子邮箱：
            <div class="weui-cell__bd weui-cell_primary">
                @Html.TextBoxFor(m => m.Email, new { validate = "{required:true,isEmail:true,messages:{required:'请输入正确email',isEmail:'请输入正确email'}}", @class = "weui-input", placeholder = "请输入正确email" })
            </div>
        </div>

        <div class="weui-form-preview__ft weui-footer_fixed-bottom">
            <a class="weui-form-preview__btn weui-form-preview__btn_primary" id="buybtn" href="javascript:void(0)" onclick="createInsurance()">立即投保</a>
        </div>
    }
</div>

<script type="text/javascript">
    $("#BirthDay").calendar();

    function createInsurance() {
        if ($("#mvcForm").valid()) {
            var certificateType = $("#CertificateType").val();
            var certificateNO = $("#CertificateNO").val();
            if (certificateType == "@((byte)UserCertificateType.IdentityCard)") {
                if (!isIdCardNo(certificateNO)) {
                    layer.alert("请输入正确的身份证号码！", { icon: 2 });
                    return false;
                }
            }
            else if (certificateType == "@((byte)UserCertificateType.Passport)") {
                if (!isPassport(certificateNO)) {
                    layer.alert("请输入正确的护照号码！", { icon: 2 });
                    return false;
                }
            }
            else if (certificateType == "@((byte)UserCertificateType.HKAndMacaoHomeCardOrTaiwanCard)") {
                if (!isHKMacao(certificateNO) || !isTaiwan(certificateNO)) {
                    layer.alert("请输入正确的港澳台通行证号码！", { icon: 2 });
                    return false;
                }
            }
            $("#mvcForm").submit();
        }
    }
</script>